package com.neusoft.neu24.dibuy.cfg;


import io.asyncer.r2dbc.mysql.MySqlConnectionConfiguration;
import io.asyncer.r2dbc.mysql.MySqlConnectionFactory;
import io.r2dbc.spi.ConnectionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;

import java.time.Duration;

/**
 * @program: learn
 * @description:
 * @author: Jingdi.Duan ,duanjingdi@msn.com
 * @create: 2024-07-08 22:15
 **/

@Configuration
@EnableR2dbcRepositories
//@EnableR2dbcRepositories

class R2DBCConfiguration extends AbstractR2dbcConfiguration {

    private static final MySqlConnectionConfiguration configuration = MySqlConnectionConfiguration.builder()
            .host("127.0.0.1")
            .user("root")
            .port(3306)
            .password("root")
            .database("dibuy")
            .createDatabaseIfNotExist(true)
            .connectTimeout(Duration.ofSeconds(3))
            .build();

    @Bean
    public ConnectionFactory connectionFactory() {
        return MySqlConnectionFactory.from(configuration);
    }
}